//
//  QKReusePool.m
//  testTool
//
//  Created by Su on 2018/12/9.
//  Copyright © 2018 com.qiankun. All rights reserved.
//

#import "QKReusePool.h"

@interface QKReusePool()


/**
 等待队列
 */
@property (nonatomic,strong) NSMutableSet   *waitingQueue;

/**
 使用中的队列
 */
@property (nonatomic,strong) NSMutableSet   *useingQueue;


@end

@implementation QKReusePool

- (instancetype)init
{
    self = [super init];
    if (self) {
        _waitingQueue  = [NSMutableSet set];
        _useingQueue   = [NSMutableSet set];
    }
    return self;
}


// 如果存在, 从等待队列中移除一个, 在使用中的队列增加一个
-(UIView *)getReuseTableView{
    UIView *view = [_waitingQueue anyObject];
    if (view == nil) {
        return nil;
    }else{
        [_waitingQueue removeObject:view];
        [_useingQueue addObject:view];
        return view;
    }
}

-(void)addViewForReusePool:(UIView *)view{
    if (view == nil) {
        return;
    }
    [_useingQueue addObject:view];
}

-(void)reset{
    UIView *view = nil;
    while ((view = [_useingQueue anyObject]) ) {
        [_useingQueue removeObject:view];
        [_waitingQueue addObject:view];
    }
}

@end
